<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>对账单</title>
    <link rel="stylesheet" type="text/css" href="../easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../plugins/font-awesome/css/font-awesome.min.css">
    <script type="text/javascript" src="../myjs/path.js"></script>
    <script src="../js/yangshi.js"></script>
    <style type="text/css">
        .list {
            list-style: none;
        }

        .list li {
            margin-top: 10px;
        }

        .list li:hover {
            background-color: #ccc
        }

        .list a {
            text-decoration: none;
            color: black;
        }

        #w {
            display: none;
        }

        .w {
            border: 1px solid #ccc;
            width: 350px;
            border-collapse: collapse;
            margin: auto;
        }

        .w td {
            border: 1px solid #ccc;
            padding: 10px;
        }

        .w tr td:nth-child(odd) {
            background-color: #eee;
        }

        .datagrid-footer {
            background-color: #f7c66c;
        }
    </style>
    <script type="text/javascript" src="../easyui/jquery.min.js"></script>
    <script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript"
            src="../easyui/locale/easyui-lang-zh_CN.js"></script>

</head>
<body>
<shiro:lacksPermission name="finance:zongzhang">没有查询此模块权限。。。</shiro:lacksPermission>
<shiro:hasPermission name="finance:zongzhang">
    <div id="cc" class="easyui-layout" data-options="fit:true">
        <table id="tbl"></table>
    </div>
    <!-- toolbar -->
    <div id="tb">
        <strong>机构:</strong>
        <input id="bumeng" class="easyui-combotree" style="width: 160px;"/>
        <strong>类型:</strong>
        <select class="easyui-combobox" name="type" id="type"
                style="width:100px;" data-options="editable:false">
            <option value="">全部</option>
            <option value="销售">销售</option>
            <option value="销售退货">销售退货</option>
            <option value="进货">进货</option>
            <option value="进货退货">进货退货</option>
            <option value="-1">出账</option>
            <option value="1">进账</option>
        </select>
        <strong>所属年季:</strong>
        <input class="easyui-combobox" id="naj" data-options="panelHeight:'auto'">
        <strong>日期查询从:</strong> <input id="startTime" type="text" class="easyui-datebox" data-options="editable:false" style="width: 120px"> 到:
        <input id="endTime" type="text" class="easyui-datebox" data-options="editable:false" style="width: 120px">
        <input class="textbox" name="wldw" placeholder="请输入往来单位" id="wldw" style="height: 25px;"/>
        <a class="easyui-linkbutton" onclick="loadGrid()" data-options="iconCls:'icon-search'"
           style="width: 70px">搜索</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="chongzhi()">重置搜索</a>
        <a iconCls="icon-save" class="easyui-linkbutton" type="button"
           onclick="downloadAccount()">导出Excel</a>
    </div>

    <input id='jgid' type="hidden" value="<%=request.getParameter("jgid")%>">
</shiro:hasPermission>
</body>
<script type="text/javascript">
    function chongzhi(){
        $("#naj").combobox("clear")
        $('#startTime').combo('setValue', '');
        $('#endTime').combo('setValue', '');
        $('#endTime').combo('clear');
        $('#startTime').combo('clear');
        $('#type').combobox("setValue","");
        $("#type").combobox("setText","全部");
        $("#wldw").val("")
        loadGrid()
    }
    $(function () {
        //加载年季
        $('#naj').combobox({
            url: path + "/finance/findnaj.do",
            valueField: 'yearandseason',
            textField: 'yearandseason',
            loadFilter: function (data) {
                return data.data
            }, onSelect: function (node) {
                /* loadGrid()*/
            }
        })
        //加载机构
        $('#bumeng').combotree({
            url: path + '/jg/tree.do',
            required: true,
            loadFilter: function (data) {
                return data.rows
            }, onLoadSuccess: function (node, data) {
                if (data.length > 0) {
                    $("#bumeng").combotree('setValue', data[0].id);
                }
                loadGrid('')
            }, onClick: function (node) {
                /* loadGrid('')*/
            }
        })

    })

   //加载数据
    function loadGrid() {
        var key = $("#wldw").val();
        var gsjg = $('#bumeng').combotree('getValue');
        var fslx = $("#type").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        if (null != endTime && '' != endTime) {
         endTime += " 23:59:59";
         }
        $("#tbl").datagrid({
            url: path + '/finance/findAccount.do',
            queryParams: {
                key: key,
                jgId: gsjg,
                fslx: fslx,
                nj: $("#naj").combobox('getValue'),
                stime: startTime,
                etime: endTime
            }
        })
    }
    //导出EXCEl
    function downloadAccount() {
        var shujuSize = $("#tbl").datagrid("getRows").length;
        if (shujuSize == 0) {
            alert("暂无数据!")
            return;
        }
        if (null != endTime && '' != endTime) {
            endTime += " 23:59:59";
        }
        window.location.href = path+"/finance/Account_report.xls?jgId=" + $('#bumeng').combotree('getValue') + "&key=" + $("#wldw").val() +
            "&fslx=" + $("#type").val() + "&stime=" + $("#startTime").val() + "&etime=" + endTime+ "&nj=" + $("#naj").combobox('getValue');
    }



    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            loadGrid()
        }

    })
    // 加载表单
    $("#tbl").datagrid({
        toolbar: '#tb',
        fit: true,
        idField: 'id',
        striped: true,
        fitColumns: false,
        singleSelect: true,
        rownumbers: true,
        nowrap: true,
        pagination: true,
        pageSize: 20,
        pageList: [10, 20, 50, 100],
        showFooter: true,
        loadMsg: '玩命加载中......',
    columns: [[{
        field: 'id',
        title: 'ID',
        width: 150,
        align: 'center',
        hidden: true
    },{
        field: 'wldwId',
        title: 'wldwId',
        width: 150,
        align: 'center',
        hidden: true
    }, {
        field: 'lsh',
        title: '流水号',
        width: 150,
        align: 'center'

    }, {
            field: 'yddid',
            title: '原订单号',
            width: 150,
            align: 'center'

        }, {
            field: 'wldwName',
            title: '往来单位',
            width: 100,
            align: 'center'
        }, {
        field: 'khtype',
        title: '往来单位类型',
        width: 100,
        align: 'center' ,
        formatter: function (value) {
                   if(value==0){
                       return "批发"
                   }else if(value==1){
                       return "分销"
                   }else if(value==2){
                       return "零售会员"
                   }else if(value==3){
                       return "供应商"
                   }else{
                       return "其他"
                   }
        }
    }, {
        field: 'yearandseason',
        title: '所属年季',
        width: 100,
        align: 'center'

    }, {
        field: 'fslx',
        title: '类型',
        width: 100,
        align: 'center',
        formatter: function (value) {
            if(value==-1){
                return "出账"
            }else if(value==1){
                return "进账"
            }else{
                return value;
            }
        }

    }, {
            field: 'amount',
            title: '交易金额',
            width: 100,
            align: 'right'

        }, {
        field: 'money',
        title: '已付金额',
        width: 100,
        align: 'right',
        formatter: function (value) {
            if (value == null)
                return value;
            return value.toFixed(2);
        }
    } , {
        field: 'zshuliang',
        title: '交易总数',
        width: 100,
        align: 'right'
    }, {
            field: 'time',
            title: '日期',
            width: 150,
            align: 'center',
            formatter: function (value) {
                if (value != null) {
                    return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
                }
            }
        }, {
            field: 'mark',
            title: '备注',
            width: 160,
            align: 'center'
        }]],
        onLoadSuccess: function () {
        $("#tbl").datagrid('selectRow', 0);
    }
    })
    // tbl end

    //格式化时间
    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S": this.getMilliseconds()
            //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
                    : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
</script>
</html>